package io.github.controller.admin;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import io.github.entity.SimSeqGroupEntity;
import io.github.entity.SysBookEntity;
import io.github.service.SimSeqGroupService;
import io.github.util.PageUtils;
import io.github.util.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Max
 * <br>
 * date 2020/2/24 9:53
 */

@RestController
@RequestMapping("/simSeqGroup")
public class SimSeqGroupController extends AbstractController{

    @Resource
    SimSeqGroupService simSeqGroupService;

    @RequestMapping("/list")
    public R list(@RequestBody JSONObject json) {
        Integer offset = json.getInteger("offset");
        Integer limit = json.getInteger("limit");
        String name = json.getString("name");

        Page<SimSeqGroupEntity> pageList = simSeqGroupService.list(offset,limit,name);
        PageUtils pageUtils = new PageUtils(pageList.getRecords(),pageList.getTotal(),pageList.getSize(),pageList.getCurrent());
        return R.ok().put("data",pageUtils);
    }

    @RequestMapping("/add")
    public R add(@RequestBody SimSeqGroupEntity entity) {
        simSeqGroupService.save(entity);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody SimSeqGroupEntity entity) {
        simSeqGroupService.update(entity);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestBody JSONObject json ) {
        JSONArray ids = json.getJSONArray("ids");
        Integer id = ids.getInteger(0);
        simSeqGroupService.delete(id);
        return R.ok();
    }
}